<template>
  <div id="dictionTopSearch2">
    <h1 class="con-right-title">
      <i class="fa fa-reply" @click="cancel"></i>
      字典管理/字典数据
    </h1>
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        :rules="rules"
        class="demo-form-inline"
      >
        <el-form-item label="字典名称">
          <el-select
            v-model="formInline.dictType"
            placeholder="请选择字典状态"
            class="long"
          >
            <el-option
              v-for="item in nameList"
              :key="item.dictType"
              :label="item.dictName"
              :value="item.dictType"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="字典标签" prop="dictLabel">
          <el-input
            v-model="formInline.dictLabel"
            placeholder="请输入关键词搜索"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="数据状态" prop="status">
          <el-select
            v-model="formInline.status"
            placeholder="请选择字典状态"
            clearable
          >
            <el-option
              v-for="item in statusList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { getDictionaryName } from '@/api/system/dictionaries' // 接口
import { sysNormalDisable } from '@utils/dictionariesFunc'
export default {
  name: 'DictionTopSearch2',
  msg: '字典管理-二级列表-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          dictType: null, // 字典名称
          dictLabel: '', // 字典标签
          status: '' // 字典状态,默认所有
        }
      }
    }
  },
  data() {
    return {
      nameList: [],
      statusList: [
        // 数据状态
        { dictLabel: '所有', dictValue: '' }
      ],
      rules: {
        dictLabel: {},
        status: {}
      }
    }
  },
  mounted() {
    this.getStatusList()
    this.getNameList()
  },
  methods: {
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
    },
    /* 获取数据状态 */
    async getStatusList() {
      let data = await sysNormalDisable(
        'sys_normal_disable',
        'sysNormalDisable'
      )
      this.statusList = this.statusList.concat(data)
    },
    /* 获取字典名称 */
    getNameList() {
      getDictionaryName((response) => {
        this.nameList = [...response]
      })
    },
    /* 取消 */
    cancel() {
      this.$router.go(-1)
    }
  }
}
</script>

<style lang="less">
#dictionTopSearch2 {
  .long {
    .el-input.el-input--suffix {
      width: 182px !important;
    }
  }
}
</style>
